package PTA2.ti56;

import java.util.Scanner;

/**
 * @author Lenovo
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String x= scanner.nextLine();
        int n=Integer.parseInt(scanner.nextLine());
        int count=0;
        int lineNumber=0;
        while (true){
            String line=scanner.nextLine();
            lineNumber++;
            if (line.equals("end")){
                break;
            }
            if (line.contains(x)){
                count++;
                System.out.println(lineNumber+" "+line);
                if (count==n){
                    break;
                }
            }
        }
        System.out.println(count);
        scanner.close();
    }
}
